import request from '@/axios'
import { RECOGNITION_API, RECTIFICATION_API, ANALYSIS_API } from '@/api/electricityApi'

// 获取电费异常数据列表
export const getElectricityAbnormalList = (params: any) => {
  return request.get({
    url: '/api/electricity-abnormal/list',
    params
  })
}

// 处理电费异常
export const processElectricityAbnormal = (data: {
  id: string
  processingResult: string
  processingMethod: string
  processingTime: string
  processor: string
}) => {
  return request.post({
    url: '/api/electricity-abnormal/process',
    data
  })
}

// 查询量费存档信息
export const queryQtyChargArchInfo = (params: any) => {
  console.log('[API请求] queryQtyChargArchInfo 参数:', params)
  console.log('[API请求] URL:', RECOGNITION_API.QUERY_INFO)

  return request.post({
    url: RECOGNITION_API.QUERY_INFO,
    data: params,
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
      'X-Requested-With': 'XMLHttpRequest'
    }
  })
}

// 导入数据
export const importData = (data: FormData) => {
  return request.post({
    url: RECOGNITION_API.IMPORT,
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 下载模板
export const downloadTemplate = () => {
  return request.get({
    url: RECOGNITION_API.DOWNLOAD_TEMPLATE,
    responseType: 'blob'
  })
}

// 异常识别
export const addAbnormalRecognition = (data: any) => {
  return request.post({
    url: RECOGNITION_API.ABNORMAL_RECOGNITION,
    data: data
  })
}

// 二次研判异常识别
export const updateQuadAbnorRntHndl = (data: any) => {
  return request.post({
    url: RECOGNITION_API.QUAD_ABNORMAL_RECOGNITION,
    data: data
  })
}

// 导出数据
export const exportData = (params: any) => {
  return request.post({
    url: RECTIFICATION_API.EXPORT,
    data: params,
    responseType: 'blob'
  })
}

// 整改提交
export const updateAbnormalRectification = (data: any) => {
  return request.post({
    url: RECTIFICATION_API.UPDATE,
    data
  })
}

// 获取工单统计
export const getOrderStats = (params: any) => {
  return request.post({
    url: ANALYSIS_API.ORDER_STATS,
    data: params
  })
}

// 获取异常类型统计
export const getAbnormalTypeStats = (params: any) => {
  return request.post({
    url: ANALYSIS_API.ABNORMAL_TYPE_STATS,
    data: params
  })
}

// 获取异常工单统计
export const getAbnormalOrderStats = (params: any) => {
  console.log('[API请求] queryQtyChargArchInfo 参数:', params)
  console.log('[API请求] URL:', RECOGNITION_API.QUERY_INFO)

  return request.post({
    url: ANALYSIS_API.ABNORMAL_ORDER_STATS,
    data: params,
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
      'X-Requested-With': 'XMLHttpRequest'
    }
  })
}

// 获取异常工单统计
export const getAbnormalOrderStatsZg = (params: any) => {
  console.log('[API请求] queryQtyChargArchInfoZg 参数:', params)
  console.log('[API请求] URL:', RECOGNITION_API.QUERY_INFO)

  return request.post({
    url: RECTIFICATION_API.QUERY_INFO,
    data: params,
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
      'X-Requested-With': 'XMLHttpRequest'
    }
  })
}
